<template>
    <view>
		<view class="header header_wi" :style="'padding-top: ' + navH + 'px;'">
		    <view class="header_height" :style="'height:' + gaodu + 'px;line-height:' + gaodu + 'px;top:' + gaodutops + 'px;'">
		        <view class="index_h_cont3">
		            <view class="index_wenben_img" @tap="jumpzuo">
		                <image src="http://daigou.sllowly.cn/assets/api/images/dzx_img33.png" mode="widthFix"></image>
		            </view>
		            <view class="index_wenben">{{$t('shangpins.title')}}</view>
		        </view>
		    </view>
		    <view class="coloe_title">s</view>
		</view>
		<view class="index_center" :style="'padding-top:' + (navH + 50) + 'px;padding-bottom: 120rpx;'">
		<scroll-view @scroll="scroll" :scroll-top="scrollTop" :scroll-y="true" >
		    <view class="containers" v-if="detail.goods_id">
		        <view class="swiper">
		            <swiper
		                :autoplay="autoplay"
		                @change="setCurrent"
		                class="banner-box swiper-box"
		                :duration="duration"
		                :indicator-dots="indicatorDots"
		                :interval="interval"
		                :circular="true"
		            >
		                <swiper-item @tap.stop.prevent="onPreviewImages" :data-index="index" v-for="(item, index) in detail.image" :key="index">
		                    <image class="slide-image" mode="aspectFill" :src="item.file_path"></image>
		                </swiper-item>
		            </swiper>
		            <view class="banner-num">
		                <text>{{ currentIndex }}</text>
		                <text>/{{ detail.image.length }}</text>
		            </view>
		        </view>
		        <view class="cont-box b-f">
		            <view class="dis-flex flex-y-center">
		                <view class="left flex-box dis-flex flex-dir-column">
		                    <!-- 商品名称 -->
		                    <view class="goods-title">
		                        <text class="title f-30 twolist-hidden">{{ detail.goods_name }}</text>
		                    </view>
		                    <!-- 商品卖点 -->
		                    <view class="goods-selling-point">
		                        <text class="f-24">{{ detail.selling_point }}</text>
		                    </view>
		                    <view class="money-box dis-flex flex-y-center">
		                        <!-- 商品价 -->
		                        <view class="goods-price">
		                            <text class="col-m f-26">￥</text>
		                            <text class="goods-price_num col-m f-40">{{ goods_price }}</text>
		                        </view>
		                        <!-- 划线价 -->
		                        <view class="line-price" v-if="line_price > 0">
		                            <text>￥{{ line_price }}</text>
		                        </view>
		                        <!-- 会员价标签 -->
		                        <view v-if="detail.is_user_grade" class="tag-grade-price">
		                            <text>{{$t('shangpins.zhekou')}}</text>
		                        </view>
		                    </view>
		                </view>
		                <!-- <view class="right goods__share">
		                    <form @submit="onClickShare" :report-submit="true">
		                        <button formType="submit" class="share-btn dis-flex flex-dir-column">
		                            <text class="share__icon iconfont icon-fenxiang"></text>
		                            <text class="f-24">{{$t('shangpins.fenxiang')}}</text>
		                        </button>
		                    </form>
		                </view> -->
		            </view>
		            <view class="goods-sales-box f-28 dis-flex col-8">
		                <text class="flex-box num">{{$t('shangpins.xiaoliang')}}：{{ detail.goods_sales }}</text>
		            </view>
		        </view>
		        <!-- 选择商品规格 -->
		        <form v-if="goodsMultiSpec.spec_attr" @submit="onToggleTrade" report-submit>
		            <button class="btn-normal" formType="submit">
		                <view class="sku-selector cont-box b-f m-top20 dis-flex flex-y-center">
		                    <view class="flex-box f-28">
		                        <text class="col-9">{{$t('shangpins.xuanze')}}：</text>
		                        <text v-for="(item, index) in goodsMultiSpec.spec_attr" :key="index">{{ item.group_name }}</text>
		                    </view>
		                    <view class="f-26 col-9 t-r">
		                        <text class="iconfont icon-xiangyoujiantou"></text>
		                    </view>
		                </view>
		            </button>
		        </form>
		        <!-- 确认购买弹窗 -->
		        <zan-popup :show="showBottomPopup" type="bottom" @close="onToggleTrade">
		            <view class="popup__trade">
		                <!-- 关闭按钮 -->
		                <view class="trade-close dis-flex flex-x-center flex-y-center" @tap.stop.prevent="onToggleTrade">
		                    <text class="iconfont icon-close f-26"></text>
		                </view>
		                <!-- 主体信息 -->
		                <view class="trade-main">
		                    <view class="goods-info dis-flex">
		                        <!-- 图片名称 -->
		                        <view class="goods-image" @tap.stop.prevent="onPreviewSkuImage">
		                            <image :src="skuCoverImage"></image>
		                        </view>
		                        <view class="right flex-box">
		                            <view class="money-box dis-flex flex-y-end">
		                                <!-- 商品价 -->
		                                <view class="goods-price">
		                                    <text class="col-m f-26">￥</text>
		                                    <text class="goods-price_num col-m f-40">{{ goods_price }}</text>
		                                </view>
		                                <!-- 划线价 -->
		                                <view class="line-price" v-if="line_price > 0">
		                                    <text>￥{{ line_price }}</text>
		                                </view>
		                            </view>
		                            <view class="goods-stock dis-flex">
		                                <text class="flex-box f-26 col-7">{{$t('shangpins.kucun')}}：{{ stock_num }}</text>
		                            </view>
		                        </view>
		                    </view>
		                    <!-- 规格列表 -->
		                    <view class="goods-attr">
		                        <!-- 滚动容器 -->
		                        <scroll-view class="goods-attr--scroll" :scroll-y="true">
		                            <view class="group-item" v-for="(attr, attr_idx) in goodsMultiSpec.spec_attr" :key="attr_idx">
		                                <view class="tips-text" :data-id="attr.group_id">{{ attr.group_name }}</view>
		
		                                <view
		                                    :class="'spec-item ' + (item.checked ? 'cur' : '')"
		                                    :data-attr-idx="attr_idx"
		                                    :data-item-idx="item_idx"
		                                    @tap.stop.prevent="onSwitchSpec"
		                                    v-for="(item, item_idx) in attr.spec_items"
		                                    :key="item_idx"
		                                >
		                                    {{ item.spec_value }}
		                                </view>
		                            </view>
		                        </scroll-view>
		                    </view>
		                    <!-- 购买数量 -->
		                    <view class="buy_number">
		                        <view class="buyNumber f-26">
		                            <text>{{$t('shangpins.goumaishul')}}</text>
		                        </view>
		                        <view class="select-number">
		                            <form @submit="onDecGoodsNumber" :report-submit="true">
		                                <button formType="submit" :class="'default ' + (goods_num > 1 ? '' : 'disabled')" type="default">-</button>
		                            </form>
		                            <input @input="onInputGoodsNum" type="number" :value="goods_num" />
		                            <form @submit="onIncGoodsNumber" :report-submit="true">
		                                <button formType="submit" class="default" type="default">+</button>
		                            </form>
		                        </view>
		                    </view>
		                </view>
		                <!-- 底部操作栏 -->
		                <view class="footer-fixed f-30">
		                    <block v-if="stock_num > 0">
		                        <view class="order-number" @tap.stop.prevent="onConfirmSubmit" data-type="addCart">{{$t('shangpins.jiaru')}}</view>
		                        <view class="order-bt" @tap.stop.prevent="onConfirmSubmit" data-type="buyNow">{{$t('shangpins.lijigoumai')}}</view>
		                    </block>
		                    <view class="default-btn" v-else>{{$t('shangpins.zanwu')}}</view>
		                </view>
		            </view>
		        </zan-popup>
		
		        <!-- 商品评价 -->
		        <view class="goods-comment" v-if="detail.comment_data.length">
		            <view class="cont-box b-f goods-property-box m-top20">
		                <text class="col-3 f-30">{{$t('shangpins.pinjia')}} ({{ detail.comment_data_count }}{{$t('shangpins.tiao')}})</text>
		                <text @tap.stop.prevent="onTargetToComment" class="comment-num">{{$t('shangpins.chakan')}}</text>
		                <view class="goods-property-jianTou">
		                    <text class="iconfont icon-xiangyoujiantou user-orderJtou" style="margin-top: 0"></text>
		                </view>
		            </view>
		            <view class="goods-comment-box b-f" v-for="(item, index) in detail.comment_data" :key="index">
		                <view class="cont-box goods-comment-box b-t b-f b-b">
		                    <view class="dis-flex">
		                        <view class="user">
		                            <text class="user_name f-26">{{ item.user.nickName }}</text>
		                        </view>
		                        <view class="com_xing">
		                            <text class="iconfont icon-shoucang active"></text>
		                            <block v-if="item.score < 30">
		                                <text class="iconfont icon-shoucang active"></text>
		                                <text class="iconfont icon-shoucang active"></text>
		                            </block>
		                            <block v-if="item.score < 20">
		                                <text class="iconfont icon-shoucang active"></text>
		                                <text class="iconfont icon-shoucang active"></text>
		                            </block>
		                        </view>
		                    </view>
		                    <view class="goods-comment-cont m-top20">
		                        <text class="f-26 twolist-hidden">{{ item.content }}</text>
		                    </view>
		                    <view class="f-22 col-9 m-top10">{{ item.create_time }}</view>
		                </view>
		            </view>
		        </view>
		
		        <!-- 商品描述 -->
		        <view class="p-bottom">
		            <view class="top-nav m-top20 b-f b-b">
		                <view class="top-nav-bar">{{$t('shangpins.miaoshu')}}</view>
		            </view>
		            <view class="order" v-if="!hiddenOrder">
		                <view v-if="detail.content != ''">
		                    <view class="b-f goods-detail-box">
		                        <!-- <view class="goods-cont-li"> -->
		                        <!-- <template is="wxParse" :data="wxParseData:content.nodes"></template> -->
		                        <mp-html :content="article_content"></mp-html>
		                        <!-- </view> -->
		                    </view>
		                </view>
		                <view v-else>
		                    <view class="yoshop-notcont">
		                        <text class="iconfont icon-wushuju"></text>
		                        <text class="cont">{{$t('shangpins.shuju')}}</text>
		                    </view>
		                </view>
		            </view>
		        </view>
		
		        <!-- 底部操作栏 -->
		        <view class="footer-fixed f-30">
		            <!-- 在线客服 -->
		            <view class="goods-fixed-icon dis-flex flex-x-center flex-y-center" @tap="freeTell" :data-phone="service_phone">
		                <button
		                    open-type="contact"
		                    sessionFrom="weapp"
		                    size="27"
		                    style="opacity: 0; position: absolute; top: 0px; left: 0px; display: block; width: 100%; height: 100%"
		                    type="default-light"
		                ></button>
		                <text class="iconfont icon-kefu"></text>
		            </view>
		            <!-- 购物车按钮 -->
		            <view @tap.stop.prevent="onTriggerCart" class="goods-fixed-icon">
		                <image class="flow-img" src="/static/images/flow.png"></image>
		                <view class="flow_num" v-if="cart_total_num > 0">
		                    <text class="">{{ cart_total_num }}</text>
		                </view>
		            </view>
		            <view class="order-number" @tap.stop.prevent="onToggleTrade">{{$t('shangpins.jiaru')}}</view>
		            <view class="order-bt" @tap.stop.prevent="onToggleTrade">{{$t('shangpins.lijigoumai')}}</view>
		        </view>
		    </view>
		</scroll-view>
		
		<!-- 返回顶部 -->
		<view @tap.stop.prevent="onScrollTop" class="widget-goTop" v-if="floorstatus">
		    <text class="iconfont icon-fanhuidingbu"></text>
		</view>
		
		<!-- 分享按钮 -->
	<!-- 	<zan-actionsheet
		    :show="share.show"
		    :actions="share.actions"
		    :cancel-text="share.cancelText"
		    :cancel-with-mask="share.cancelWithMask"
		    @cancel="onCloseShare"
		    @actionclick="onClickShareItem"
		    mask-class="tiny"
		/>
		 -->
		<!-- 商品海报 弹出层 -->
		<zan-popup :show="share.showPopup" @close="onTogglePopup">
		    <view class="pop-poster pop-example__container">
		        <!-- 关闭按钮 -->
		        <view class="pop-close dis-flex flex-x-center flex-y-center" @tap.stop.prevent="onTogglePopup">
		            <text class="iconfont icon-shanchu f-30 col-9"></text>
		        </view>
		        <form @submit="onSavePoster" :report-submit="true">
		            <view class="poster__image">
		                <image mode="widthFix" :src="qrcode"></image>
		            </view>
		            <view class="poster__tips m-top10 t-c"></view>
		            <view class="padding-box m-top10 profile-btn">
		                <button formType="submit">{{$t('shangpins.baocun')}}</button>
		            </view>
		        </form>
		    </view>
		</zan-popup>
		</view>
       
    </view>
</template>

<script>
import zanActionsheet from "@/components/actionsheet/index.vue";
import zanPopup from "@/components/popup/index.vue";
const app = getApp(); // 富文本插件

const util = require('../../utils/util.js'); // 记录规格的数组
let request = require('../../utils/require');

let goodsSpecArr = [];
export default {
	components: {
	  zanActionsheet,
	  zanPopup,
	  // shortcut,
	},
	data() {
            return {
				navH: 0,
				gaodu: app.globalData.height,
				gaodutops: app.globalData.top,
              indicatorDots: true,
			  service_phone:uni.getStorageSync('service_phone'),

              // 是否显示面板指示点
              autoplay: true,

              // 是否自动切换
              interval: 3000,

              // 自动切换时间间隔
              duration: 800,

              // 滑动动画时长
              currentIndex: 1,

              // 轮播图指针
              floorstatus: false,

              // 返回顶部
              showView: true,

              // 显示商品规格
              detail: {
                goods_id: "",
                image: [],
                goods_name: "",
                selling_point: "",
                is_user_grade: "",
                goods_sales: "",
                comment_data: {
                  length: ""
                },
                comment_data_count: "",
                content: ""
              },

              // 商品详情信息
              goods_price: 0,

              // 商品价格
              line_price: 0,

              // 划线价格
              stock_num: 0,

              // 库存数量
              goods_num: 1,

              // 商品数量
              goods_sku_id: 0,

              // 规格id
              cart_total_num: 0,

              // 购物车商品总数量
              goodsMultiSpec: {
                spec_attr: ""
              },

              // 多规格信息
              // 分享按钮组件
              share: {
                show: false,
                cancelWithMask: true,
                cancelText: '关闭',
                actions: [{
                  name: '生成商品海报',
                  className: 'action-class',
                  loading: false
                }, {
                  name: '发送给朋友',
                  openType: 'share'
                }],
                // 商品海报
                showPopup: false
              },

              skuCoverImage: "",
              scrollTop: 0,
              showBottomPopup: false,
              attr_idx: 0,

              attr: {
                group_id: "",
                group_name: "",
                spec_items: []
              },

              hiddenOrder: "",
              article_content: "",
              qrcode: ""
            };
        },
/**
* 生命周期函数--监听页面加载
*/
onLoad(e) {
  let _this = this;
  let scene = app.globalData.getSceneData(e);
  if (e.goods_id) {
    _this.goods_id = e.goods_id;
  } else {
    _this.goods_id = scene.gid;
  } // 获取商品信息
  _this.getGoodsDetail();
},
/**
* 分享当前页面
*/
onShareAppMessage() {
  var _this = this;
  var thisUserInfo = uni.getStorageSync('userInfo');
  var sett =  uni.getStorageSync('setting');
  var shareObj = {
  	title: sett.name,
  	desc: sett.desc,
  	// 默认是小程序的名称(可以写SOGO express集运等)
  	path: '/pages/goods/index?scene=uid%3A' + thisUserInfo.user_id +'&goods_id=' +  _this.goods_id,
  	// 默认是当前页面，必须是以‘/’开头的完整路径
  	imageUrl: '',
  	//自定义图片路径，可以是本地文件路径、代码包文件路径或者网络图片路径，支持PNG及JPG，不传入 imageUrl 则使用默认截图。显示图片长宽比是 5:4
  	success: function(res) {
  		// 转发成功之后的回调
  		if (res.errMsg == 'shareAppMessage:ok') {
  		}
  	},
  	fail: function() {
  		// 转发失败之后的回调
  		if (res.errMsg == 'shareAppMessage:fail cancel') {
  			// 用户取消转发
  		} else {
  			if (res.errMsg == 'shareAppMessage:fail') {
  			}
  		}
  	}
  };
  return shareObj;
},
methods: {
	//拨打电话
	freeTell: function (e) {
	    uni.makePhoneCall({
	        phoneNumber: e.currentTarget.dataset.phone
	    });
	},
	jumpzuo() {
	    uni.navigateBack()
	},
    /**
     * 获取商品信息
     */
    getGoodsDetail() {
      let _this = this;
	  var data = {
		  goods_id: _this.goods_id
	  }
	  request.get(`index.php?s=/api/goods/detail&wxapp_id=` + uni.getStorageSync('web_id'), data).then(res => {
	  	if (res.data.code == 1) {
			var da = _this._initGoodsDetailData(res.data.data);
	  		_this.detail = da.detail;
			_this.goods_price = da.goods_price;
			_this.stock_num = da.stock_num;
			_this.skuCoverImage = da.skuCoverImage;
			_this.line_price = da.line_price;
	  	}
	  });
    },

    /**
     * 初始化商品详情数据
     */
    _initGoodsDetailData(data) {
      let _this = this; // 商品详情
      let goodsDetail = data.detail; // 富文本转码
      if (goodsDetail.content.length > 0) {
        //wxParse.wxParse('content', 'html', goodsDetail.content, _this, 0)
        _this.article_content = _this.escape2Html(goodsDetail.content);;
      } // 商品价格/划线价/库存


      data.goods_sku_id = goodsDetail.goods_sku.spec_sku_id;
      data.goods_price = goodsDetail.goods_sku.goods_price;
      data.line_price = goodsDetail.goods_sku.line_price;
      data.stock_num = goodsDetail.goods_sku.stock_num; // 商品封面图(确认弹窗)

      data.skuCoverImage = goodsDetail.goods_image; // 多规格商品封面图(确认弹窗)

      if (goodsDetail.spec_type == 20 && goodsDetail.goods_sku['image']) {
        data.skuCoverImage = goodsDetail.goods_sku['image']['file_path'];
      } // 初始化商品多规格
      if (goodsDetail.spec_type == 20) {
        data.goodsMultiSpec = _this._initManySpecData(goodsDetail.goods_multi_spec);
      }
	  console.log(data,88989)
      return data;
    },

    /**
     * 初始化商品多规格
     */
    _initManySpecData(data) {
      goodsSpecArr = [];

      for (let i in data.spec_attr) {
        for (let j in data.spec_attr[i].spec_items) {
          if (j < 1) {
            data.spec_attr[i].spec_items[0].checked = true;
            goodsSpecArr[i] = data.spec_attr[i].spec_items[0].item_id;
          }
        }
      }

      return data;
    },

    /**
     * 点击切换不同规格
     */
    onSwitchSpec(e) {
      let _this = this;

      let attrIdx = e.currentTarget.dataset.attrIdx;
      let itemIdx = e.currentTarget.dataset.itemIdx;
      let goodsMultiSpec = _this.goodsMultiSpec;
      ;

      for (let i in goodsMultiSpec.spec_attr) {
        for (let j in goodsMultiSpec.spec_attr[i].spec_items) {
          if (attrIdx == i) {
            goodsMultiSpec.spec_attr[i].spec_items[j].checked = false;

            if (itemIdx == j) {
              goodsMultiSpec.spec_attr[i].spec_items[itemIdx].checked = true;
              goodsSpecArr[i] = goodsMultiSpec.spec_attr[i].spec_items[itemIdx].item_id;
            }
          }
        }
      }

      _this.goodsMultiSpec = goodsMultiSpec
      // 更新商品规格信息
      _this._updateSpecGoods();
    },

    /**
     * 更新商品规格信息
     */
    _updateSpecGoods() {
      let _this = this;
      let specSkuId = goodsSpecArr.join('_');
      let spec_list = _this.goodsMultiSpec.spec_list;
      let skuItem = spec_list.find(val => {
        return val.spec_sku_id == specSkuId;
      });
      ; // 记录goods_sku_id
      // 更新商品价格、划线价、库存

      if (typeof skuItem === 'object') {
          _this.goods_sku_id= skuItem.spec_sku_id,
          _this.goods_price = skuItem.form.goods_price,
          _this.line_price = skuItem.form.line_price,
          _this.stock_num = skuItem.form.stock_num,
          _this.skuCoverImage = skuItem.form.image_id > 0 ? skuItem.form.image_path : _this.detail.goods_image
      }
    },

    /**
     * 设置轮播图当前指针 数字
     */
    setCurrent(e) {
      let _this = this;
      _this.currentIndex = e.detail.current + 1
    },

    /**
     * 返回顶部
     */
    onScrollTop(t) {
      let _this = this;
      _this.scrollTop = 0
    },

    /**
     * 显示/隐藏 返回顶部按钮
     */
    scroll(e) {
      let _this = this;
      _this.floorstatus = e.detail.scrollTop > 200
    },

    /**
     * 增加商品数量
     */
    onIncGoodsNumber(e) {
      let _this = this;
      app.globalData.saveFormId(e.detail.formId);
      _this.goods_num = ++_this.goods_num
    },

    /**
     * 减少商品数量
     */
    onDecGoodsNumber(e) {
      let _this = this;
      app.globalData.saveFormId(e.detail.formId);
      if (_this.goods_num > 1) {
        _this.goods_num = --_this.goods_num
      }
    },

    /**
     * 自定义输入商品数量
     */
    onInputGoodsNum(e) {
      let _this = this;
      let iptValue = e.detail.value;
      if (!util.isPositiveInteger(iptValue) && iptValue !== '') {
        iptValue = 1;
      }
      _this.goods_num = iptValue
    },

    /**
     * 跳转购物车页面
     */
    onTriggerCart() {
      uni.navigateTo({
        url: "../flow/index"
      });
    },

    /**
     * 加入购物车and立即购买
     */
    onConfirmSubmit(e) {
      let _this = this;
      let submitType = e.currentTarget.dataset.type;
      if (submitType === 'buyNow') {
        // 立即购买
        uni.navigateTo({
          url: '../flow/checkout?' + util.urlEncode({
            order_type: 'buyNow',
            goods_id: _this.goods_id,
            goods_num: _this.goods_num,
            goods_sku_id: _this.goods_sku_id
          }),
          success() {
            // 关闭弹窗
            _this.onToggleTrade();
          }

        });
      } else {
		if(uni.getStorageSync('token')){
			if (submitType === 'addCart') {
				// 加入购物车
				var data = {
					  goods_id: _this.goods_id,
					  goods_num: _this.goods_num,
					  goods_sku_id: _this.goods_sku_id,
					  token: uni.getStorageSync('token')
				}
				request.post(`index.php?s=/api/cart/add&wxapp_id=` + uni.getStorageSync('web_id'), data).then((res) => {
				    if (res.data.code == 1) {
						uni.showToast({
						    title: res.data.msg,
						    icon: 'none'
						});
						_this.cart_total_num = res.data.data.cart_total_num
				    } else {
				        uni.showToast({
				            title: res.data.msg,
				            icon: 'none'
				        });
				    }
				});
			}
		}
		else{
        console.log("哈哈哈")
        uni.showToast({
        	title:_this.$t('shangpins.denglu'),
        	icon:'none'
        	
        })
		}
	  
	  }
	  
    },

    /**
     * 表单验证
     */
    _onVerify() {
      let _this = this;

      if (_this.goods_num === '') {
        app.globalData.showError(_this.$t('shangpins.weigoumai'));
        return false;
      } // 将购买数量转为整型，防止出错


      _this.goods_num = parseInt(_this.goods_num)

      if (_this.goods_num <= 0) {
        app.globalData.showError(_this.$t('shangpins.weigoumais'));
        return false;
      }

      return true;
    },

    /**
     * 浏览商品图片
     */
    onPreviewImages(e) {
      let _this = this;
      let index = e.currentTarget.dataset.index;
      let imageUrls = [];
      _this.detail.image.forEach(item => {
        imageUrls.push(item.file_path);
      });

      uni.previewImage({
        current: imageUrls[index],
        urls: imageUrls
      });
    },

    /**
     * 预览Sku规格图片
     */
    onPreviewSkuImage(e) {
      let _this = this;

      uni.previewImage({
        current: _this.skuCoverImage,
        urls: [_this.skuCoverImage]
      });
    },

    /**
     * 跳转到评论
     */
    onTargetToComment() {
      let _this = this;

      uni.navigateTo({
        url: './comment/comment?goods_id=' + _this.goods_id
      });
    },

    /**
     * 显示分享选项
     */
    onClickShare(e) {
      let _this = this; // 记录formId
      app.globalData.saveFormId(e.detail.formId);
      _this.share.show = true
    },

    /**
     * 关闭分享选项
     */
    onCloseShare() {
      let _this = this;
      _this.share.show = false
    },

    /**
     * 点击生成商品海报
     */
    onClickShareItem(e) {
      let _this = this;
console.log(e,"eeeeeee??")
      if (e.detail.index === 0) {
        // 显示商品海报
        _this._showPoster();
      }

      _this.onCloseShare();
    },

    /**
     * 切换商品海报
     */
    onTogglePopup() {
      let _this = this;
      _this.share.showPopup = !_this.share.showPopup
    },

    /**
     * 显示商品海报图
     */
    _showPoster() {
      let _this = this;

      uni.showLoading({
        title: _this.$t('m.jiazai')
      });

      app.globalData._get('goods/poster', {
        goods_id: _this.goods_id
      }, result => {
        _this.setData(result.data, () => {
          _this.onTogglePopup();
        });
      }, null, () => {
        uni.hideLoading();
      });
    },

    /**
     * 保存海报图片
     */
    onSavePoster(e) {
      let _this = this; // 记录formId


      app.globalData.saveFormId(e.detail.formId);
      uni.showLoading({
        title: _this.$t('m.jiazai')
      }); // 下载海报图片

      uni.downloadFile({
        url: _this.qrcode,

        success(res) {
          uni.hideLoading(); // 图片保存到本地

          uni.saveImageToPhotosAlbum({
            filePath: res.tempFilePath,

            success(data) {
              uni.showToast({
                title: _this.$t('shangpins.baocuncg'),
                icon: 'success',
                duration: 2000
              }); // 关闭商品海报

              _this.onTogglePopup();
            },

            fail(err) {
              console.log(err.errMsg);

              if (err.errMsg === 'saveImageToPhotosAlbum:fail auth deny') {
                uni.showToast({
                  title: _this.$t('shangpins.yunxu'),
                  icon: "none",
                  duration: 1000
                });
                setTimeout(() => {
                  uni.openSetting();
                }, 1000);
              }
            },

            complete(res) {
              console.log('complete'); // wx.hideLoading();
            }

          });
        }

      });
    },

    /**
     * 确认购买弹窗
     */
    onToggleTrade(e) {
      let _this = this;
      if (typeof e === 'object') {
        // 记录formId
        if (e.detail.hasOwnProperty('formId')) {
          app.globalData.saveFormId(e.detail.formId);
        }
      }
      _this.showBottomPopup = !_this.showBottomPopup
    }
}
                };
</script>
<style>
@import './index.css';
</style>
